<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCartStore } from '@/stores/cart'

// 当前激活的标签页
const activeTab = ref(0)


// 底部导航切换
const onTabChange = (index: number) => {
  activeTab.value = index
}

const cartStore = useCartStore()
const cartCount = computed(() => cartStore.cartCount)

</script>

<template>
  <div id="app">
    <!-- 路由视图 -->
    <router-view />

    <!-- 底部导航 -->
    <van-tabbar v-model="activeTab" @change="onTabChange" fixed>
      <van-tabbar-item icon="home-o" to="/">首页</van-tabbar-item>
      <van-tabbar-item icon="apps-o" to="/category">分类</van-tabbar-item>
      <van-tabbar-item icon="cart-o" to="/cart">
        购物车
        <template #badge>
          <van-badge v-if="cartCount > 0" :content="cartCount" />
        </template>
      </van-tabbar-item>
      <van-tabbar-item icon="user-o" to="/profile">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<style scoped>
.mobile-mall {
  width: 100%;
  min-height: 100vh;
  background-color: #f7f8fa;
}

.search-bar {
  position: sticky;
  top: 0;
  z-index: 100;
}

.banner-swipe {
  height: 180px;
  margin-bottom: 16px;
}

.banner-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 16px;
  background: white;
  margin-bottom: 12px;
}

.category-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
}

.category-name {
  font-size: 12px;
  color: #646566;
  margin-top: 8px;
}

.section {
  background: white;
  margin-bottom: 12px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #ebedf0;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #323233;
  margin: 0;
}

.section-more {
  font-size: 12px;
  color: #969799;
}

.product-card {
  position: relative;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s ease;
}

.product-card:active {
  transform: scale(0.98);
}

.product-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #ee0a24;
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 1;
}

.product-image {
  width: 100%;
  height: 160px;
  object-fit: cover;
}

.product-info {
  padding: 12px;
}

.product-title {
  font-size: 14px;
  color: #323233;
  margin: 0 0 8px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.product-price {
  color: #ee0a24;
  font-size: 16px;
  font-weight: 600;
}

.content {
  padding: 16px;
}
</style>
